home *** CD-ROM | disk | FTP | other *** search
/ Fifty: Elektronik / FIFTY Elektronik (PS_Computer_Vertrieb).iso / ps8 / fty1017 / gepackt.exe / DISK2 / PLOTSRC.EXE / LIBACCES.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-11-10  |  3.7 KB  |  146 lines

  1. Unit LIBACCES;
  2. {$I-}
  3. Interface
  4.  
  5. Uses  Dos,StrTool,Geddefs;
  6.  
  7. Const Max_Lib_Size=255;
  8.  
  9.       LIB_FILEID  ='DYLIB510';
  10.  
  11. Type  Dir_Entry =Record
  12.                   Case Word of
  13.                    1: {alle Verzeichnis-Einträge(Index 1..N) }
  14.                      (Macroname :NameStr;
  15.                       NrOfRecs  :Word;
  16.                       FileOffset:Longint;  { für Seek }
  17.                       Date      :Longint);
  18.                   0: {Nur Verzeichnis-Eintrag 0 }
  19.                      (FILEID          :NameStr;
  20.                       NrOfDirEntries  :Word;
  21.                       UsedBLDRecs:Longint;  { Anzahl gültigen BLD-Records in Benutzung }
  22.                       TotalSize  :Longint); { Anzahl der BLD-Records ohne DIR-Size }
  23.                  end;
  24. Const
  25.    Dir_Header_Size=(Sizeof(Dir_Entry)*(Max_Lib_Size+1)) div SizeOf(BildElement);
  26.                    { Größe des Directory-Headers in Bildelementen }
  27.  
  28. Type
  29.   Dir_Table =Array[0..Max_Lib_Size] of Dir_Entry;
  30.  
  31.   Dir_Buffer=Record
  32.                Case Boolean of
  33.                  true:(DIR:Dir_table);
  34.                  false:(HEADER:Array[0..Dir_Header_Size] of Bildelement);
  35.                end;
  36.  
  37. Function Find_In_Dir(Name:NameStr;Var Verz:Dir_Table):Word;
  38.   { 0 , wenn nicht gefunden, index in DIR-TABLE wenn gefunden }
  39.  
  40. Function Get_Dir_Buff(Var F:File;Var DirBuff:Dir_Buffer):Boolean;
  41. { liest Dir-Buffer einer Datei, und öffnet Datei}
  42.  
  43. Function Put_Dir_Buff(Var F:File;Var DirBuff:Dir_Buffer):Boolean;
  44. { schreibt Dir-Buffer einer Datei, und öffnet Datei }
  45.  
  46. Function Find_in_Lib(Var LibFile:PathStr;Name:NameStr;Var E:Dir_Entry):Boolean;
  47. { sucht nach MACRO <Name> in LIB-Datei Libfile }
  48.  
  49. Procedure CloseF(Var F :File);
  50.  
  51. implementation
  52.  
  53. Function Find_In_Dir(Name:NameStr;Var Verz:Dir_Table):Word;
  54. Var First,Last,Try :Word;
  55. begin
  56.   Find_In_Dir:=0;
  57.   Try:=0;
  58.   First:=1;
  59.   Last:=Verz[0].NrofDirEntries;
  60.   UpStr(Name);
  61.   While (First<=Last) Do { Binäre Suche im Sortierten Array }
  62.    begin
  63.     Try:=(First+Last) div 2;
  64.     With Verz[Try] do
  65.       begin
  66.         If Name>Macroname then
  67.           First:=Succ(Try)
  68.         else
  69.           If Name<Macroname then
  70.             Last:=Pred(Try)
  71.           else
  72.             begin
  73.               Find_In_Dir:=Try;
  74.               Exit;
  75.              end;
  76.       end;
  77.     end;
  78. end;
  79.  
  80. Procedure CloseF(Var F :File);
  81. Var Dummy:Word;
  82. begin
  83.   Inc(No_blink);
  84.   Close(F);
  85.   DummY:=IoResult;
  86.   Dec(No_blink);
  87. end;
  88.  
  89. Function Get_Dir_Buff(Var F:File;Var DirBuff:Dir_Buffer):Boolean;
  90. Var Dummy:Word;
  91. begin
  92.   Get_Dir_Buff:=false;
  93.   Inc(No_blink);
  94.   Reset(F,Sizeof(BildElement));
  95.   Dec(No_blink);
  96.   If Ioresult<>0 then begin CloseF(F);Exit; end;
  97.   Inc(No_blink);
  98.   BlockRead(F,DirBuff,Succ(Dir_Header_Size));
  99.   Dec(No_blink);
  100.   If Ioresult<>0 then begin CloseF(F);Exit; end;
  101.   IF DirBuff.DIR[0].FILEID<>LIB_FileID then
  102.     begin CloseF(F); Exit; end;
  103.   Get_Dir_Buff:=True;
  104. end;
  105.  
  106. Function Put_Dir_Buff(Var F:File;Var DirBuff:Dir_Buffer):Boolean;
  107. Var Dummy:Word;
  108. begin
  109.   Put_Dir_Buff:=false;
  110.   Inc(No_blink);
  111.   Reset(F,Sizeof(BildElement));
  112.   Dec(No_blink);
  113.   If Ioresult<>0 then begin CloseF(F);Exit; end;
  114.   Inc(No_blink);
  115.   BlockWrite(F,DirBuff,Succ(Dir_Header_Size));
  116.   Dec(No_blink);
  117.   If Ioresult<>0 then begin CloseF(F);Exit; end;
  118.   Put_Dir_Buff:=True;
  119. end;
  120.  
  121. Function Find_in_Lib(Var LibFile:PathStr;Name:NameStr;Var E:Dir_Entry):Boolean;
  122. Var V :Dir_buffer;
  123.     F :File;
  124.     Idx:Word;
  125. begin
  126.   Find_In_Lib:=false;
  127.   FillChar(E,Sizeof(E),0);
  128.   Inc(No_blink);
  129.   Assign(F,LibFile);
  130.   If Get_Dir_Buff(F,V) then
  131.     begin
  132.       Idx:=Find_In_Dir(Name,V.DIR);
  133.       If Idx>0 then
  134.       begin
  135.         E:=V.DIR[Idx];
  136.         Find_In_Lib:=true;
  137.       end;
  138.     end;
  139.   CloseF(F);
  140.   Dec(No_blink);
  141. end;
  142.  
  143.  
  144.  
  145. end.
  146.